
student_info_list = []

def check_list_notnone():
    '''开启程序，先判断列表 没整明白，先放着'''
    if not student_info_list:
        print('学生信息为空，请先输入用户信息')
    else:
        print('')

def print_menu():
    print("-"*30)
    print(" 学生管理系统 V1.0")
    print(" 1:添加学生")
    print(" 2:删除学生")
    print(" 3:修改学生")
    print(" 4:查询学生")
    print(" 5:显示所有学生")
    print(" 6:退出系统")
    print("-"*30)

def add_student_info():
    """添加学生信息"""
    global student_info_list

    # new_num = i
    new_name = input("请输入姓名:")
    new_tel = input("请输入手机号:")
    new_qq = input("请输入QQ:")
    # 添加学生
    # 此用户名已经被占用,请重新输入
    for student_info in student_info_list:
        if new_name == student_info['name']:
            print("此用户名已经被占用,请重新输入")
            return

    # 定义一个字典，用来存储用户的学生信息,name,tel,qq
    student_info_jihe = {}
    # 向字典中添加数据
    # student_info_jihe["num"] = new_num
    student_info_jihe["name"] = new_name
    student_info_jihe["tel"] = new_tel
    student_info_jihe["qq"] = new_qq
    # 向列表中添加这个字典
    student_info_list.append(student_info_jihe)
    f = open('student.txt', 'w')
    f.write(str(student_info_list))
    f.close()

def delete_student():
    """删除学生信息"""
    print(len(student_info_list))
    delete_num = int(input("请输入要删除的序号:"))
    # 判断输入是否符合范围
    if 0 <= delete_num <= len(student_info_list):
        del_com = input("你确定要删除么?yes or no\n")
        if del_com == "no":
            print('no,返回')
        else:
            del student_info_list[delete_num-1]
            print('删除成功')
            # 此处有点疑问，录入是序号不是固定的，
    else:
        print("输入序号有误,请重新输入")

def modify_student_info():
    """修改学生信息"""

def search_student_info():
    """查询学生信息"""
    check_student_name = str(input('请输入需要查询的名称\n'))
    if not student_info_list:
        print('学生信息为空，请先输入用户信息')
    else :
        for student_info in student_info_list:
            if check_student_name == student_info['name']:
                print('查到以下信息')
                print('用户:%s,电话:%s,qq:%s' % (student_info['name'], student_info['tel'], student_info['qq']))
            else:
                print('不存在该用户')


def print_all_info():
    """显示学生信息"""
    i = 1
    if not student_info_list:
        print('学生信息为空，请先输入用户信息')
    else:
        for student_info in student_info_list:
            print("%d\t%s\t\t%s\t\t%s" % (i, student_info['name'], student_info['tel'], student_info['qq']))
            i += 1
def main():
    while True:
        print_menu()

        num = input("请输入要进行的操作(数字)\n")

        if num == "1":
            # 添加用户
            add_student_info()
        elif num == "2":
            # 删除用户
            delete_student()
        elif num == "3":
            # 修改信息
            modify_student_info()
        elif num == "4":
            # 查询
            search_student_info()
        elif num == "5":
            # 显示所有
            print_all_info()
        elif num == "6":
            exit_str = input("退出,yes或者no\n")
            if exit_str == "yes":
                break
            elif exit_str == "no":
                main()
            else:
                print("\n输入有误,请重新输入！！")
        else:
            print("\n输入有误,请重新输入")
        input("\n按回车键继续！！")
# 执行main
main()